home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-10-15 | 8.5 KB | 273 lines | [TEXT/MPS ] |
- /*
- * File: Configuration.cp
- *
- * Contains: xxx put contents here xxx
- *
- * Written by: P. Nagarajan
- *
- * Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
- *
- * Change History (most recent first):
- *
- * 3/26/93 NAGA xxx put comment here xxx
- *
- * To Do:
- */
-
- #ifndef __Configuration__
- #include "Configuration.h"
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __TRAPS__
- #include <traps.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __THREADS__
- #include <Threads.h>
- #endif
-
- typedef long *LongIntPtr;
-
- //—————————————————————————————————————————————————————————————————————————————————————
- // Global Variables
- //—————————————————————————————————————————————————————————————————————————————————————
- extern Configuration gConfiguration;
- extern Ptr gStrippedAddress;
-
-
-
- long StripLong(void * address)
- {
- return ((long)address & (long)gStrippedAddress);
- } // StripLong
-
- void BlockSet( Ptr destPtr,
- long byteCount,
- unsigned char setVal )
- {
- Ptr endPtr = NULL;
- unsigned long longSetVal = 0;
- LongIntPtr longEndPtr = NULL;
- LongIntPtr longSetValPtr;
-
- destPtr = (Ptr)StripLong(destPtr);
- endPtr = (Ptr)(destPtr + byteCount);
-
- //longEndPtr = (LongIntPtr)(destPtr + (byteCount & 0xFFFFFFFC));//Trunc to nearest 4 bytes
- longEndPtr = (LongIntPtr)((long)(destPtr + byteCount) & 0xFFFFFFFC);//Trunc to nearest 4 bytes
-
- //We do longword assignments when we have a chance
- if (byteCount >= 4)
- {
- //if ((((long)destPtr) & 1) == 1) //Starting on an odd byte boundary
- while (((long)destPtr) & 0x00000003) //Starting on an odd byte boundary
- *destPtr++ = setVal;
-
- longSetVal = (setVal << 24) + (setVal << 16) + (setVal << 8) + setVal;// Lets get a 4 byte 'punch'.
-
- //Assign in 4 byte chunks what we can
- for (longSetValPtr = (LongIntPtr)destPtr; longSetValPtr < longEndPtr;)
- *longSetValPtr++ = longSetVal;
- destPtr = (Ptr)longSetValPtr;
- }
-
- //Now finish assigning odd bytes
- while (destPtr < endPtr)
- *destPtr++ = setVal;
- } // BlockSet
-
- pascal TrapType GetTrapType(short theTrap)
-
- {
- // OS traps start with A0, Tool with A8 or AA.
- if ((theTrap & 0x0800) == 0) // per D.A.
- return OSTrap;
- else
- return ToolTrap;
- } // GetTrapType
-
- //----------------------------------------------------------------------------------------
- // NumToolboxTraps: InitGraf is always implemented (trap 0xA86E). If the trap table is
- // big enough, trap 0xAA6E will always point to either Unimplemented or some other trap,
- // but will never be the same as InitGraf. Thus, you can check the size of the trap table
- // by asking if the address of trap 0xA86E is the same as 0xAA6E.
- //----------------------------------------------------------------------------------------
- #pragma segment Configuration
-
- short NumToolboxTraps()
- {
- if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
- return 0x200;
- else
- return 0x400;
- } // NumToolboxTraps
-
- //----------------------------------------------------------------------------------------
- // TrapExists:
- //----------------------------------------------------------------------------------------
- #pragma segment Configuration
-
- pascal Boolean TrapExists(short theTrap)
- {
- TrapType theTrapType = GetTrapType(theTrap);
- short localTrap = theTrap; // since theTrap is a const
- if (theTrapType == ToolTrap)
- {
- localTrap = (localTrap & 0x07FF);
- if (localTrap >= NumToolboxTraps())
- localTrap = _Unimplemented;
- }
-
- return NGetTrapAddress(_Unimplemented, ToolTrap) != NGetTrapAddress(localTrap, theTrapType);
- } // TrapExists
-
-
-
- //----------------------------------------------------------------------------------------
- // HasGestaltAttr:
- //----------------------------------------------------------------------------------------
- #pragma segment Configuration
-
- Boolean HasGestaltAttr(OSType itsAttr,
- short itsBit)
-
- {
- long response = 0;
-
- return (Gestalt(itsAttr, &response) == noErr) && (((response >> itsBit) & 1) != 0);
- } // HasGestaltAttr
-
-
- //----------------------------------------------------------------------------------------
- // DefineConfiguration:
- //----------------------------------------------------------------------------------------
- #pragma segment Configuration
- void DefineConfiguration(Configuration& theConfiguration)
- {
- const short mDesktopBus = 0x0400;
-
- OSErr err;
- long response;
-
- // -1 == 0xFFFFFFFF, the largest 32 bit address. Our routine StripLong uses a
- // pre-stripped address gStrippedAddress to avoid the yucky MPW glue.
- gStrippedAddress = StripAddress((Ptr) - 1);
-
- err = Gestalt(gestaltVersion, &response);
- theConfiguration.environsVersion = (short)response;
-
- err = Gestalt(gestaltMachineType, &response);
- theConfiguration.machineType = (short)response;
-
- theConfiguration.hasROM128K = theConfiguration.machineType >= gestaltMac512KE;
- if (theConfiguration.hasROM128K)
- theConfiguration.hasHFS = true; // assume 128K and later ROMs all have HFS
- else
- // theConfiguration.hasHFS = GetFSFCBLen() > 0;
- theConfiguration.hasHFS = false;
-
- err = Gestalt(gestaltSystemVersion, &response);
- theConfiguration.systemVersion = (short)response;
-
- err = Gestalt(gestaltProcessorType, &response);
- theConfiguration.processor = (short)response;
-
- err = Gestalt(gestaltFPUType, &response);
- theConfiguration.hasFPU = response != gestaltNoFPU;
-
- err = Gestalt(gestaltQuickdrawVersion, &response);
- theConfiguration.hasColorQD = response != gestaltOriginalQD;
-
- err = Gestalt(gestaltQuickdrawVersion, &response);
- theConfiguration.has32BitQD = theConfiguration.hasColorQD && (response != gestalt8BitQD);
-
- err = Gestalt(gestaltKeyboardType, &response);
- theConfiguration.keyboardType = (short)response;
-
- err = Gestalt(gestaltAppleTalkVersion, &response);
- theConfiguration.atDrvrVersNum = (short)response;
-
- theConfiguration.hasSCSI = HasGestaltAttr(gestaltHardwareAttr, gestaltHasSCSI);
-
- err = Gestalt(gestaltAUXVersion, &response);
- theConfiguration.hasAUX = response != 0;
-
- err = Gestalt(gestaltScriptMgrVersion, &response);
- theConfiguration.hasScriptManager = theConfiguration.hasROM128K && (response != 0);
-
- theConfiguration.hasTempMem = HasGestaltAttr(gestaltOSAttr, gestaltTempMemSupport);
-
- err = Gestalt(gestaltTextEditVersion, &response);
- theConfiguration.teVersion = response;
-
- //theConfiguration.hasDesktopBus = (GetHardwareConfigurationFlags() & mDesktopBus) > 0;
-
- theConfiguration.hasHierarchicalMenus = theConfiguration.hasROM128K && TrapExists(_PopUpMenuSelect);
-
- theConfiguration.hasStyleTextEdit = theConfiguration.systemVersion >= 0x600;
- theConfiguration.hasSoundManager = theConfiguration.hasROM128K && TrapExists(_SndDoCommand);
- theConfiguration.hasWaitNextEvent = theConfiguration.hasROM128K && TrapExists(_WaitNextEvent);
-
- // System 7.0 support
- theConfiguration.hasAppleEventMgr = HasGestaltAttr(gestaltAppleEventsAttr, gestaltAppleEventsPresent);
- theConfiguration.hasAppleEventMgr101 = HasGestaltAttr(gestaltAppleEventsAttr, gestaltScriptingSupport);
- theConfiguration.hasEditionMgr = HasGestaltAttr(gestaltEditionMgrAttr, gestaltEditionMgrPresent);
- theConfiguration.hasHelpMgr = HasGestaltAttr(gestaltHelpMgrAttr, gestaltHelpMgrPresent);
- theConfiguration.hasAliasMgr = HasGestaltAttr(gestaltAliasMgrAttr, gestaltAliasMgrPresent);
- theConfiguration.hasFolderMgr = HasGestaltAttr(gestaltFindFolderAttr, gestaltFindFolderPresent);
- theConfiguration.hasPopupCDEF = HasGestaltAttr(gestaltPopupAttr, gestaltPopupPresent);
- theConfiguration.hasTrueType = HasGestaltAttr(gestaltFontMgrAttr, gestaltOutlineFonts);
-
-
- // ask process mgr for several values
- if (theConfiguration.systemVersion >= 0x700)
- {
- theConfiguration.hasProcessMgr = HasGestaltAttr(gestaltOSAttr, gestaltLaunchControl);
- theConfiguration.hasThreadMgr = HasGestaltAttr(gestaltThreadMgrAttr, gestaltThreadMgrPresent);
- //theConfiguration.hasThreadMgr = false;
-
- ProcessSerialNumber psn;
- psn.highLongOfPSN = 0;
- psn.lowLongOfPSN = kCurrentProcess;
-
- ProcessInfoRec info;
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = NULL;
- info.processAppSpec = NULL;
-
- if (GetProcessInformation(&psn, &info) == noErr)
- {
- theConfiguration.isOnlyBackground = (info.processMode & modeOnlyBackground) ? true : false;
- theConfiguration.isHighLevelEventAware = (info.processMode & modeHighLevelEventAware) ? true : false;
- }
- else
- {
- theConfiguration.isOnlyBackground = false;
- theConfiguration.isHighLevelEventAware = false;
- }
- }
- else
- {
- theConfiguration.hasProcessMgr = false;
-
- theConfiguration.isOnlyBackground = false;
- theConfiguration.isHighLevelEventAware = false;
- }
- } // DefineConfiguration
-